#ifndef __UART_H__
#define __UART_H__

//#define UART_TEST_ENABLE

//#define STR_ECHO_ENABLE

#define UART_GET_LEN_ALWAYS 0
#define UART_GET_WAIT_INFINITE (~0)

typedef enum{
	UART_BR_9600=9600,
	UART_BR_38400=38400,
	UART_BR_115200=115200
}UART_BUADRATE_E;

typedef enum {
	RS232_DEVICE_1,
	RS232_DEVICE_2,
	RS232_DEVICE_3,
	UART_DEVICE_4,
	RS232_DEVICE_5,
	UART_DEVICE_BUTT
}UART_DEVICE_E;

typedef struct RS232_DESC_T{
	USART_TypeDef *p_dev;
	unsigned int speed;
	unsigned char *rx_buf;
	volatile unsigned rx_in;
	volatile unsigned rx_out;
	unsigned char *tx_buf;
	volatile unsigned tx_in;	
	volatile unsigned tx_out;
	volatile unsigned tx_idle;
	unsigned int rx_size;
	unsigned int tx_size;
}RS232_DESC_T;

int uart_init(void);
int uart_get_buf(UART_DEVICE_E dev, unsigned char *pbuf, unsigned int receive_len, unsigned int wait_ms);
int uart_get_str(UART_DEVICE_E dev, unsigned char *str, int32_t str_len);
int uart_transmit_ready(UART_DEVICE_E dev);
int uart_transmit_buf(UART_DEVICE_E dev, unsigned char *buf, unsigned int len);
int uart_transmit_string(UART_DEVICE_E dev, unsigned char *str);
int uart_putc(UART_DEVICE_E dev, unsigned char ch);
int uart_receive_clear(UART_DEVICE_E dev);

#ifdef YTIS_MOTION_INPUT_ENABLE
int32_t motion_input(char *pchar);
#endif

void USART1_IRQHandler(void);
void USART2_IRQHandler(void);
void USART3_IRQHandler(void);
void UART4_IRQHandler(void);
void UART5_IRQHandler(void);

#endif

